/**
 * 自定义的共用函数
 * */

//var domain = 'http://tsh.jiuge_mc.com'; //本地域名
var domain = 'http://tsh.fuzhuangchangongxiao.cn'; //云端域名
var prefix = 'admin'; //URL前缀
var adminAccess = 'webqSoiKwpWVge4TkaryH6MKvOdceGt7ZMaF20g8H0cnXIweb'; //电脑端接口权限值
var userInfo = 'userInfo'; //登陆信息键名
var outVideoList = 'outVideoList'; //外部视频键名
var stockList = 'stockList'; //库视频键名


/**
 * 获取域名
 * */
function getDomain(){
    return domain + '/' + prefix;
}


/**
 * 左侧菜单
 * */
function getLeftMenus(){
    var menus = [ //左侧菜单列表
        {
            "name":"首页",
            "title":"回到首页",
            "link":"/admin/index.html",
            //"aClass":"active",
            "iClass":"home"
        },
        {
            "name":"外部视频",
            "title":"第三方视频",
            "link":"/admin/video.html",
            "iClass":"table"
        },
        {
            "name":"库视频",
            "title":"特效库",
            "link":"/admin/stock.html",
            "iClass":"table"
        },
        {
            "name":"用户创单",
            "title":"用户创作单",
            "link":"/admin/plus.html",
            "iClass":"table"
        },
        {
            "name":"用户创板",
            "title":"用户创作面版进行时",
            "link":"/admin/board.html",
            "iClass":"table"
        },
        {
            "name":"渲染订单",
            "title":"用户的渲染订单",
            "link":"/admin/order.html",
            "iClass":"table"
        },
        {
            "name":"直播测试",
            "title":"直播测试",
            "link":"/admin/live.html",
            "iClass":"table"
        }
    ];
    var view = getUrlParam('view');
    view = view=='' ? 0: view;
    //console.log(view)
    //view页面索引，page当前页码
    var m = '';
    for (var i=0;i<menus.length;i++) {
        var param = menus[i].link+'?view='+i+'&page=0';
        m += '<li class="sidebar-nav-link">';
        if (i==view) {
            //m += '<a href="'+menus[i].link+'?view='+i+'" class="active">';
            m += '<a href="'+param+'" class="active" title="'+menus[i].title+'">';
        } else {
            //m += '<a href="'+menus[i].link+'?view='+i+'">';
            m += '<a href="'+param+'" title="'+menus[i].title+'">';
        }
        m += '<i class="am-icon-'+menus[i].iClass+' sidebar-nav-link-logo"></i>';
        m += menus[i].name;
        m += '</a>';
        m += '</li>';
    }
    //console.log(menus);
    $(".sidebar-nav")[0].innerHTML = m;
}


/**
 * 登陆人资料
 * */
function getLoginUser(){
    var logo = '', userInfo = '', theme = '';
    //后台logo
    logo += '<a href="javascript:;"> <img src="assets/img/logo.png" style="width:30px;"> </a>';
    $(".tpl-header-logo").html(logo);
    //登陆人信息
    userInfo += '<div class="tpl-user-panel-slide-toggleable">';
    userInfo += '<div class="tpl-user-panel-profile-picture">';
    userInfo += '<img src="assets/img/user04.png">';
    userInfo += '</div>';
    userInfo += '<span class="user-panel-logged-in-text">';
    userInfo += '<i class="am-icon-circle-o am-text-success tpl-user-panel-status-icon"></i>';
    userInfo += '禁言小张';
    userInfo += '</span>';
    userInfo += '<a href="javascript:;" class="tpl-user-panel-action-link">';
    userInfo += '<span class="am-icon-pencil"></span> 账号设置';
    userInfo += '</a>';
    userInfo += '</div>';
    $(".tpl-sidebar-user-panel").html(userInfo);
    //主体切换
    theme += '<div class="tpl-skiner-toggle am-icon-cog"></div>';
    theme += '<div class="tpl-skiner-content">';
    theme += '<div class="tpl-skiner-content-title">';
    theme += '选择主题';
    theme += '</div>';
    theme += '<div class="tpl-skiner-content-bar">';
    theme += '<span class="skiner-color skiner-white" data-color="theme-white"></span>';
    theme += '<span class="skiner-color skiner-black" data-color="theme-black"></span>';
    theme += '</div>';
    theme += '</div>';
    $(".tpl-skiner").html(theme);
}


/**
 * 新订单提醒
 * */
function getNewOrder(){
    var h = '';
    h += '<a href="javascript:;" class="am-dropdown-toggle" data-am-dropdown-toggle>';
    h += '<i class="am-icon-bell"></i>';
    h += '<span class="am-badge am-badge-warning am-round item-feed-badge">5</span>';
    h += '</a>';
    h += '<ul class="am-dropdown-content tpl-dropdown-content">';
    h += '<li class="tpl-dropdown-menu-notifications">';
    h += '<a href="javascript:;" class="tpl-dropdown-menu-notifications-item am-cf">';
    h += '<div class="tpl-dropdown-menu-notifications-title">';
    h += '<i class="am-icon-line-chart"></i>';
    h += '<span> 有6笔新的销售订单</span>';
    h += '</div>';
    h += '<div class="tpl-dropdown-menu-notifications-time">';
    h += '12分钟前';
    h += '</div>';
    h += '</a>';
    h += '</li>';
    h += '</ul>';
    $("#orderNewList").html(h);
}





/**
 * 缓存处理
 * */
//缓存获取
function cacheGet(key){
    var cacheStr = localStorage.getItem(key);
    var cache = JSON.parse(cacheStr);
    return cache;
}
//缓存设置
function cacheSet(key,val){
    //把数组转换为对象存入
    var str = JSON.stringify(val);
    localStorage.setItem(key,str);
    return true;
}
//缓存删除
function cacheDel(key){
    localStorage.removeItem(key);
}
//缓存删除
function cacheClear(){
    localStorage.clear();
}





/**
 * URL中，获取指定参数
 * paramName URL中需要获取的参数键名
 * */
function getUrlParam(paramName) {
    var url = document.location.toString();
    var arrObj = url.split("?");
    if (arrObj.length > 1) {
        var arrParam = arrObj[1].split("&");
        var arr;
        for (var i = 0; i < arrParam.length; i++) {
            arr = arrParam[i].split("=");
            if (arr != null && arr[0] == paramName) {
                return decodeURI(arr[1]);
            }
        }
        return "";
    }
    else {
        return "";
    }
}


/**
 * 用js限制字数，超出部分以省略号...显示
 * str 字符串
 * num 显示的字数
 * */
function getStrLimitNum(str,num) {
    var strNew = '';
    if (str.length <= num) {
        strNew = str;
    } else {
        strNew = str.substr(0,num) + '...' ;
    }
    return strNew;
}


/**
 * 构建自定义提示弹窗
 * @param msg 自定义提示信息
 * */
function getSelfPop(msg){
    var pop = '';
    //pop += '<div id="selfPop">';
    pop += '<style type="text/css">#selfPopDiv { width:100%;height:100%;min-height:800px;background:0;position:fixed;bottom:0;z-index:10000; } #selfPopMask { margin:0 40%;padding:5px 10px;width:20%;background:#000000;border-radius:5px;color:#FFFFFF;text-align:center;position:fixed;bottom:100px;z-index:10000; } </style>';
    //pop += '<div id="selfPopDiv"> <div id="selfPopMask">'+msg+'</div>';
    pop += '<div id="selfPopDiv"> <div id="selfPopMask">'+msg+'， <span id="selfPopTime">2</span> 秒后消失</div> </div>';
    //pop += '<script type="text/javascript">setInterval(function(){$("#selfPop").fadeOut();$("#selfPop").html("");},2000); setTimeout(function(){var selfPopTime = $("#selfPopTime").html();if (selfPopTime > 0) {selfPopTime = selfPopTime * 1 - 1;$("#selfPopTime").html(selfPopTime);}},1000);</script>';
    pop += '<script type="text/javascript">setInterval(function(){$("#selfPop").html("");},2000); setTimeout(function(){var selfPopTime = $("#selfPopTime").html();if (selfPopTime > 0) {selfPopTime = selfPopTime * 1 - 1;$("#selfPopTime").html(selfPopTime);}},1000);</script>';
    //pop += '<script type="text/javascript">setInterval(function(){$("#selfPop").html("");},2000);</script>';
    //pop += '</div>';
    $("#selfPop").html(pop);
    //$("#selfPop").fadeIn();
}